import { UPDATEPAGENEWJOBINTENTION } from '../types/pagenewjobintention'
import { createAction } from 'redux-actions'
import { getUserArchiveInfoRequest } from '../../../../service/user-archive-controller'

export const DOREQUESTNEWJOBINTENTION = createAction(UPDATEPAGENEWJOBINTENTION, payload => {
  return new Promise(resolve => {
    getUserArchiveInfoRequest({ ...payload }).then(({ data }) => {
      const { entry, code } = data
      if (code === 200) {
        let wantWork = entry && entry.archive && entry.archive.jobHuntingModels || []
        resolve({
          networkerror: false,
          showEmpty: false,
          wantWork,
          userArchiveModel: entry && entry.archive && entry.archive.userArchiveModel || {}
        })
      } else {
        resolve({
          networkerror: true
        })
      }
    })
  })
})
